package com.ratp.expertisetechnique;

import android.app.TabActivity;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.Typeface;
import android.os.Bundle;
import android.view.Gravity;
import android.view.ViewGroup;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;
import android.widget.TextView;

@SuppressWarnings("deprecation")
public class ToutesLesExpertises extends TabActivity {

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		creationOnglet();
	}

	private void creationOnglet() {
		setContentView(R.layout.toutes_les_expertises);
		{
			// **********************Creation
			// d'onglets*******************************
			TabHost tabHost = (TabHost) findViewById(android.R.id.tabhost);
			/** tid1 is firstTabSpec Id. Its used to access outside. */
			TabSpec firstTabSpec = tabHost.newTabSpec("tid1");
			TabSpec secondTabSpec = tabHost.newTabSpec("tid1");
			/** TabSpec setIndicator() is used to set name for the tab. */
			/**
			 * TabSpec setContent() is used to set content for a particular tab.
			 */
			firstTabSpec.setIndicator("Toutes les expertises").setContent(
					new Intent(this, FirstOngletToutesLesExpertises.class));
			secondTabSpec.setIndicator("Nouvelle expertise").setContent(
					new Intent(this, NouvelleExprtise.class));
			/** Add tabSpec to the TabHost to display. */
			tabHost.addTab(firstTabSpec);
			tabHost.addTab(secondTabSpec);
			// *****************************************************

			// ############coloration des onglets########################
			for (int i = 0; i < tabHost.getTabWidget().getChildCount(); i++) {
				tabHost.getTabWidget().getChildAt(i)
						.setBackgroundColor(Color.parseColor("#60a0ff"));
				// int tabCount = tabHost.getTabWidget().getTabCount();

				// ++++++++++Coloration du text en noir+++++++++++++++++++++
				TextView tv = (TextView) tabHost.getTabWidget().getChildAt(i)
						.findViewById(android.R.id.title);
				tv.setTextColor(Color.BLACK);
				// tv.setTextAppearance(this, Style bold);

				tv.setTypeface(null, Typeface.BOLD_ITALIC);
				tv.setTextSize(15);

				// +++++++++++++++++++++++++++++++

				// --------------alignement du text au
				// milieu----------------------
				if (tv != null) {
					// reduce height of the tab
					// tv.getLayoutParams().height *=0.66;

					// get title text view
					if (tv instanceof TextView) {
						// just in case check the type

						// center text
						((TextView) tv).setGravity(Gravity.CENTER);
						// wrap text
						((TextView) tv).setSingleLine(false);

						// explicitly set layout parameters
						tv.getLayoutParams().height = ViewGroup.LayoutParams.FILL_PARENT;
						tv.getLayoutParams().width = ViewGroup.LayoutParams.WRAP_CONTENT;
						// ------------------------------------
					}
				}
				// To set different color for current selected tab. use
				tabHost.getTabWidget().getChildAt(0)
						.setBackgroundColor(Color.parseColor("#00a0a0"));
			}
			// ####################################
		}
	}
}
